package com.shitou.shitoumember.controller;

import com.shitou.shitoucommons.annotation.CheckUserLogin;
import com.shitou.shitoucommons.utils.PageUtils;
import com.shitou.shitoumember.entity.MemberInterestEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.shitou.shitoumember.service.MemberInterestService;
import com.shitou.shitoucommons.utils.RespBean;

import java.util.Arrays;
import java.util.Map;


/**
 * 关注表
 *
 * @author shitouren
 * @email 3076767823@qq.com
 * @date 2023-04-04 16:23:15
 */
@Api(value = "会员关注其他会员")
@RestController
@RequestMapping("shitoumember/memberinterest")
public class MemberInterestController {
    @Autowired
    private MemberInterestService memberInterestService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public RespBean list(@RequestParam Map<String, Object> params){
        PageUtils page = memberInterestService.queryPage(params);

        return RespBean.success().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public RespBean info(@PathVariable("id") Long id){
        MemberInterestEntity memberInterest = memberInterestService.getById(id);

        return RespBean.success().put("memberInterest", memberInterest);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public RespBean save(@RequestBody MemberInterestEntity memberInterest){
        memberInterestService.save(memberInterest);

        return RespBean.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public RespBean update(@RequestBody MemberInterestEntity memberInterest){
        memberInterestService.updateById(memberInterest);

        return RespBean.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public RespBean delete(@RequestBody Long[] ids){
        memberInterestService.removeByIds(Arrays.asList(ids));

        return RespBean.success();
    }

    /**
     * 创建关注信息
     * @param memberId
     * @param beingMemberId
     * @return
     */
    @ApiOperation(value = "创建被关注人的和关注人的信息，需要登录校验")
    @CheckUserLogin
    @PostMapping("/createInterest")
    public RespBean createInterest(@RequestParam Long memberId, @RequestParam Long beingMemberId){
        return memberInterestService.createInterest(memberId, beingMemberId);
    }


    /**
     * 删除关注信息
     * @param memberId
     * @param beingMemberId
     * @return
     */
    @ApiOperation(value = "删除被关注人的信息，采用真实删除, 需要登陆校验")
    @CheckUserLogin
    @PostMapping("/deleteInterest")
    public RespBean deleteInterest(@RequestParam Long memberId, @RequestParam Long beingMemberId){
        return memberInterestService.deleteInterest(memberId, beingMemberId);
    }


    /**
     * 获取用户关注的所有用户
     * @param memberId
     * @return
     */
    @ApiOperation(value = "获取当前登录会员关注的所有会员，需要登录校验")
    @CheckUserLogin
    @PostMapping("/getInterest")
    public RespBean getInterest(@RequestParam Long memberId){
        return memberInterestService.getInterest(memberId);
    }

}
